<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="824.44">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; min-height: 15.0px}
p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #bf0000}
p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000}
p.p9 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000; min-height: 12.0px}
span.s1 {color: #003af3}
span.s2 {color: #002bb5}
span.s3 {color: #000000}
span.s4 {color: #0000bf}
span.s5 {color: #606060}
span.Apple-tab-span {white-space:pre}
</style>
</head>
<body>
<p class="p1"><b>FFTCrest<span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>Spectral crest measure</b></p>
<p class="p2"><br></p>
<p class="p3"><b><span class="Apple-tab-span">	</span>FFTCrest.kr(chain, freqlo, freqhi)</b></p>
<p class="p2"><br></p>
<p class="p3">Given an <a href="SC://FFT"><span class="s1">FFT</span></a> <b>chain</b>, this produces the <i>spectral crest measure</i>, which is an indicator of the "peakiness" of the spectral energy distribution. For example, white noise should produce a flat (non-peaky) spectrum, and therefore a low value for the spectral crest.</p>
<p class="p2"><br></p>
<p class="p3">Optionally, <b>freqlo</b> and <b>freqhi</b> indicate the lower and upper frequency limits of the band to look at; by default, the whole FFT range (excluding DC and nyquist) is analysed.</p>
<p class="p2"><br></p>
<p class="p3">In pseudo-equation form, the measure is calculated as follows:</p>
<p class="p2"><br></p>
<p class="p3"><span class="Apple-tab-span">	</span>Crest = S.maxItem / S.mean</p>
<p class="p2"><br></p>
<p class="p3">where "S" is a list of the squared magnitudes in the spectral band. Note that this limits the value to being greater than or equal to 1. (Some research uses a logarithmic scale - you can apply the logarithm yourself if required.)</p>
<p class="p2"><br></p>
<p class="p3">See also: <a href="FFTFlatness.help.rtf"><span class="s1">FFTFlatness</span></a> (which provides a similar type of feature)</p>
<p class="p2"><br></p>
<p class="p2"><br></p>
<p class="p3"><b>Examples</b></p>
<p class="p4"><br></p>
<p class="p5">s.boot;</p>
<p class="p5">b = <span class="s2">Buffer</span>.alloc(s,2048,1);</p>
<p class="p6"><br></p>
<p class="p5">(</p>
<p class="p7"><span class="s3">{ </span>// Example - vary mixture of white noise and pure tone with the mouse</p>
<p class="p8"><span class="s4">var</span> in, chain, crest;</p>
<p class="p8">in = <span class="s4">XFade2</span>.ar(<span class="s4">WhiteNoise</span>.ar, <span class="s4">SinOsc</span>.ar, <span class="s4">MouseX</span>.kr(-1,1));</p>
<p class="p8">chain = <span class="s4">FFT</span>(b.bufnum, in);</p>
<p class="p8"><span class="s4">Out</span>.ar(0, in.dup * 0.1);</p>
<p class="p9"><br></p>
<p class="p8">crest = <span class="s4">FFTCrest</span>.kr(chain);</p>
<p class="p9"><br></p>
<p class="p8"><span class="s4">Out</span>.kr(0, crest.poll(10, <span class="s5">"crest"</span>));</p>
<p class="p8">}.play;</p>
<p class="p5">)</p>
<p class="p6"><br></p>
<p class="p5">(</p>
<p class="p7"><span class="s3">{ </span>// Same as above but subbands rather than whole spectrum. move mouse up&amp;down too...</p>
<p class="p8"><span class="s4">var</span> in, chain, crest1, crest2;</p>
<p class="p8">in = <span class="s4">XFade2</span>.ar(<span class="s4">WhiteNoise</span>.ar, <span class="s4">Blip</span>.ar(numharm: <span class="s4">MouseY</span>.kr(200, 1, 1)), <span class="s4">MouseX</span>.kr(-1,1));</p>
<p class="p8">chain = <span class="s4">FFT</span>(b.bufnum, in);</p>
<p class="p8"><span class="s4">Out</span>.ar(0, in.dup * 0.1);</p>
<p class="p9"><br></p>
<p class="p8">crest1 = <span class="s4">FFTCrest</span>.kr(chain, 100, 2000);</p>
<p class="p8">crest2 = <span class="s4">FFTCrest</span>.kr(chain, 2000, 10000);</p>
<p class="p9"><br></p>
<p class="p8"><span class="s4">Out</span>.kr(0, [crest1.poll(10, <span class="s5">"crest1"</span>), crest2.poll(10, <span class="s5">"crest2"</span>)]);</p>
<p class="p8">}.play;</p>
<p class="p5">)</p>
</body>
</html>
